package com.bootx.job;

import com.bootx.entity.Config;
import com.bootx.service.ConfigService;
import com.bootx.service.RedPackageInfoService;
import com.bootx.service.RedPackageService;
import com.bootx.service.RedisService;
import com.bootx.util.JsonUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Map;

/**
 * @author black
 */
@Component
public class ImageJob {

    @Resource
    private RedPackageService redPackageService;
    @Resource
    private RedPackageInfoService redPackageInfoService;
    @Resource
    private RedisService redisService;

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Resource
    private ConfigService configService;

    @Value("${job}")
    private Integer job;

    //@Scheduled(fixedRate = 1000)
    private void run() {
        redPackageService.parse(null);
    }

    //@Scheduled(fixedRate = 1000)
    private void run1() {
        if(job==0){
            return;
        }
        try {
            Map<String, Object> map = jdbcTemplate.queryForMap("select id,predictSeconds from redpackageinfo order by sn desc limit 1;");
            if(map.get("predictSeconds")!=null){
                return;
            }
        }catch (Exception e) {
            System.out.println("没有数据");
            return;
        }
        redPackageInfoService.updateIsRob2();


//        int winCount = 0;
//        int loseCount = 0;
//        try {
//            winCount = Integer.parseInt(redisService.get("win"));
//        }catch (Exception ignored){}
//        try {
//            loseCount = Integer.parseInt(redisService.get("fail"));
//        }catch (Exception ignored){}
//        // 连续失败超过2次（包含），调整预测规则
//        if (loseCount<2){
//            redPackageInfoService.updateIsRob2((loseCount+1) * 5, 8);
//        }else{
//            redPackageInfoService.updateIsRob2((loseCount+1) * 5, 8);
//        }
    }
}
